﻿using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using SlamDunk.CMS.Model.DataModel;

namespace SlamDunk.CMS.Model.ViewModel
{
    /// <summary>
    /// Link视图模型类
    /// </summary>
    [Serializable]
    public class LinkView
    {
        #region 01.属性——Id
        /// <summary>
        /// 属性——Id
        /// </summary>
        public int Id { get; set; }
        #endregion

        #region 02.属性——CategoryId
        /// <summary>
        /// 属性——CategoryId
        /// </summary>
        [Required(ErrorMessage = "必填")]
        [DisplayName("类别Id")]
        [RegularExpression(@"\d+", ErrorMessage = "必须是数字")]
        public int CategoryId { get; set; }
        #endregion

        #region 02.属性——CategoryName
        /// <summary>
        /// 属性——CategoryName
        /// </summary>
        [DisplayName("类别名称")]
        public string CategoryName { get; set; }
        #endregion

        #region 03.外键属性——LinkCategory
        /// <summary>
        /// 外键属性——LinkCategory
        /// </summary>
        public LinkCategory LinkCategory { get; set; }
        #endregion

        #region 04.属性——LinkName
        /// <summary>
        /// 属性——LinkName
        /// </summary>
        [Required(ErrorMessage = "必填")]
        [DisplayName("链接名称")]
        [StringLength(32, ErrorMessage = "内容过长")]
        public string LinkName { get; set; }
        #endregion

        #region 05.属性——Url
        /// <summary>
        /// 属性——Url
        /// </summary>
        [Required(ErrorMessage = "必填")]
        [DisplayName("链接地址")]
        [StringLength(256, ErrorMessage = "内容过长")]
        public string Url { get; set; }
        #endregion

        #region 06.属性——Description
        /// <summary>
        /// 属性——Description
        /// </summary>
        [Required(ErrorMessage = "必填")]
        [DisplayName("链接描述")]
        [StringLength(256, ErrorMessage = "内容过长")]
        public string Description { get; set; }
        #endregion

        #region 07.属性——Sort
        /// <summary>
        /// 属性——Sort
        /// </summary>
        [Required(ErrorMessage = "必填")]
        [RegularExpression(@"\d+", ErrorMessage = "必须是数字")]
        [Range(0, 100000, ErrorMessage = "数字过大")]
        [DisplayName("排序")]
        public int Sort { get; set; }
        #endregion

        #region 08.属性——ImagePath
        /// <summary>
        /// 属性——ImagePath
        /// </summary>
        [DisplayName("图片")]
        [StringLength(256, ErrorMessage = "内容过长")]
        public string ImagePath { get; set; }
        #endregion

        #region 09.属性——AddTime
        /// <summary>
        /// 属性——AddTime
        /// </summary>
        public string AddTime { get; set; }
        #endregion

        #region 10.方法——转换为数据模型
        /// <summary>
        /// 转换为数据模型
        /// </summary>
        /// <returns>Link数据模型对象</returns>
        public Link ToDataModel()
        {
            return new Link()
            {
                Id = this.Id,
                CategoryId = this.CategoryId,
                LinkName = this.LinkName,
                Url = this.Url,
                Description = this.Description,
                Sort = this.Sort,
                ImagePath = this.ImagePath,
                DelFlag = false,
                AddTime = DateTime.Now
            };
        }
        #endregion
    }
}
